Skip to content

Conversation

@zlwu
Copy link
Contributor

@zlwu zlwu commented Aug 24, 2022

Add RolesGuard guard and and Roles decorator to support Role-Based Access Control.

This is an example for users with role USER or ADMIN can call updateUser().

@Resolver(() => User)
@UseGuards(GqlAuthGuard)
export class UsersResolver {

  // ...


  @Roles(Role.USER, Role.ADMIN)
  @UseGuards(GqlAuthGuard, RolesGuard)
  @Mutation(() => User)
  async updateUser(
    @UserEntity() user: User,
    @Args('data') newUserData: UpdateUserInput
  ) {
    return this.usersService.updateUser(user.id, newUserData);
  }

  // ...
}

@zlwu zlwu changed the title add role guard and decorator Add role guard and decorator to support RBAC Aug 24, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant